From: Marcin Cieślak Date: Wed, 14 Mar 2012 20:20:53 +0000 (+0000) Subject: Rename "user" and "text" when upgrading on PostgreSQL X-Git-Tag: 1.31.0-rc.0~24136 X-Git-Url: http://git.cyclocoop.org/%27%20.%20%24prefix%20.%20Wiki::transformTitleToURI%28%24matches%5B1%5D%29%20.%20%27?a=commitdiff_plain;h=556c5cf464b9103b04b247ed7dd7ee3051e9aef6;p=lhc%2Fweb%2Fwiklou.git Rename "user" and "text" when upgrading on PostgreSQL Follow-up to r15791. You can lie to me, but not to your installer. Make DatabasePostgres::tableExists to check for real table names, not faked ones. DatabasePostgres is currently lying to the rest of the MediaWiki that "mwuser" table is actually called "user" and that "pagecontents" is called "text". While MediaWiki does not care, the installer (and updater do). This allows us to overcome first hurdle in getting MediaWiki 1.7.3 to update to trunk on PostgreSQL and uncover further bugs. For this commit to actually do something, we rename those tables when upgrading to match what we have in maintenance/postgres/tables.sql And by the way, tell installer not to check for "user" table, since most PostgreSQL users will have "mwuser" instead. Picking "archive" instead. Patchset2: wrapped commit message at 72 chars Change-Id: Ic874e92bb1adda3430d3292423d4f3617c25456c --- diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 6452f54069..e2b38f5203 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -708,14 +708,19 @@ class DatabasePostgres extends DatabaseBase { # Replace reserved words with better ones switch( $name ) { case 'user': - return 'mwuser'; + return $this->realTableName( 'mwuser', $format ); case 'text': - return 'pagecontent'; + return $this->realTableName( 'pagecontent', $format ); default: - return parent::tableName( $name, $format ); + return $this->realTableName( $name, $format ); } } + /* Don't cheat on installer */ + function realTableName( $name, $format = 'quoted' ) { + return parent::tableName( $name, $format ); + } + /** * Return the next in a sequence, save the value for retrieval via insertId() * @return null @@ -990,7 +995,7 @@ class DatabasePostgres extends DatabaseBase { if ( !$schema ) { $schema = $this->getCoreSchema(); } - $table = $this->tableName( $table, 'raw' ); + $table = $this->realTableName( $table, 'raw' ); $etable = $this->addQuotes( $table ); $eschema = $this->addQuotes( $schema ); $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n " diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index 14604c162b..046fa16431 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -158,7 +158,7 @@ abstract class DatabaseInstaller { } $this->db->selectDB( $this->getVar( 'wgDBname' ) ); - if( $this->db->tableExists( 'user', __METHOD__ ) ) { + if( $this->db->tableExists( 'archive', __METHOD__ ) ) { $status->warning( 'config-install-tables-exist' ); $this->enableLB(); return $status; diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index d4412cb2e2..6b3cb514e8 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -27,6 +27,11 @@ class PostgresUpdater extends DatabaseUpdater { */ protected function getCoreUpdateList() { return array( + # rename tables 1.7.3 + # r15791 Change reserved word table names "user" and "text" + array( 'renameTable', 'user', 'mwuser'), + array( 'renameTable', 'text', 'pagecontent'), + # new sequences array( 'addSequence', 'logging_log_id_seq' ), array( 'addSequence', 'page_restrictions_pr_id_seq' ), @@ -406,7 +411,8 @@ END; protected function renameTable( $old, $new ) { if ( $this->db->tableExists( $old ) ) { $this->output( "Renaming table $old to $new\n" ); - $old = $this->db->addQuotes( $old ); + $old = $this->db->realTableName( $old, "quoted" ); + $new = $this->db->realTableName( $new, "quoted" ); $this->db->query( "ALTER TABLE $old RENAME TO $new" ); } }